package cn.itsource.easyexcel.write;

import cn.itsource.constant.Constant;
import cn.itsource.util.GenerateUserUtil;
import cn.itsource.vo.User;
import cn.itsource.vo.User2;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.read.metadata.holder.ReadSheetHolder;
import com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder;
import com.alibaba.excel.write.metadata.WriteSheet;

import java.io.File;


/**
 * 在已存在的excel文件中  追加数据
 */
public class WriteDemo7 {
    public static void main(String[] args) {
        //先创建一个excel文件
        String filename = Constant.BATH_URL + "user7.xlsx";
        // 向Excel中写入数据
        EasyExcel.write(filename, User     .class)
                .sheet("用户信息")
                .doWrite(GenerateUserUtil.getUserData());


        //在已有的excel文件中   追加数据
        File file = new File(Constant.BATH_URL + "user7.xlsx");
        File tempFile = new File(Constant.BATH_URL + "temp.xlsx");
        EasyExcel.write(file, User.class)
                .needHead(false).//不使用表头对象
                withTemplate(file).file(tempFile).sheet().doWrite(GenerateUserUtil.getUserData());



    }
}
